package com.example.daytest.manyThread;

import java.util.concurrent.*;

/**
 * @author heyu
 * @title: TestThreadPool
 * @description: 线程池
 * @date 2023/3/10下午5:07
 */
public class TestThreadPool {
    public static void main(String[] args) {
        ExecutorService service=new ThreadPoolExecutor(3,5,1000, TimeUnit.MICROSECONDS,new ArrayBlockingQueue<>(5));
//        //ExecutorService service= Executors.newFixedThreadPool(3);
//       // ExecutorService service= Executors.newSingleThreadExecutor();
//
//
//
        for (int i = 0; i < 5; i++) {
            service.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("当前线程那么"+Thread.currentThread().getName()+"======");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        service.shutdown();
//        while (true){
//            threadDemo();
//            try {
//                Thread.sleep(2000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }





    }


    private static void threadDemo(){
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(1,10,100,TimeUnit.SECONDS,new ArrayBlockingQueue<>(100));
        threadPoolExecutor.execute(()->{
            System.out.println();
        });
    }
}
